var total = 0;
var pageSize = 20;
var pageNo = 1;
$(document).ready(function(){   
	getUserEvaluation();
});

$('#user-evaluation-box').on('click','.delete',function(){
	console.log($(this).parent().parent().parent().data('evaluation-id'))
	removeEvaluation($(this).parent().parent().parent().data('evaluation-id'))
});

// 评价删除
function removeEvaluation(id){
	$.ajax({
    url: baseUrl+"/hsent-xxyl-user/service/deleteEvaluate",
    type:"get",	
    data:"id="+id,	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
				getUserEvaluation();
      }
    },
    error:function(res){
          
    },
  })
}

// 获取我的评价
function getUserEvaluation(){
	$.ajax({
    url: baseUrl+"/hsent-xxyl-user/service/selectEvaluation",
    type:"get",	
		data:"page="+pageNo+
		"&index="+pageSize,	
    dataType:"json", 
    success:function(res){
			console.log(res);
      if(res.status === 1){
				var tempData = res.data;
				for(var i = 0 ; i < tempData.length ; i ++){
					tempData[i].round = tempData[i].evaluateValue==null?0:Math.round(tempData[i].evaluateValue);
					tempData[i].cha = 5 - tempData[i].round;
					tempData[i].evaluateImg = tempData[i].evaluateImg.split(',');
					tempData[i].tBasicsShop.entResno = tempData[i].tBasicsShop.entResno.substring(0,2)+' '+
					tempData[i].tBasicsShop.entResno.substring(2,5)+' '+
					tempData[i].tBasicsShop.entResno.substring(5,7)+' '+
					tempData[i].tBasicsShop.entResno.substring(7,11);
				}
				total = res.total;
				var data={
					data:tempData,
					pirUrl:pirUrl
				}
				console.log(data)
				var html = template('user-script', data);
				document.getElementById('user-evaluation-box').innerHTML = html;
				layuiPage();
			};
    },
    error:function(res){
					
    },
  })
}

// layui 分页器
function layuiPage(){
	layui.use('laypage', function(){
		var laypage = layui.laypage;
		//执行一个laypage实例
		laypage.render({
			elem: 'Pagination', //注意，这里的 test1 是 ID，不用加 # 号
			count: total, //数据总数，从服务端得到
			limits:[20,30,40,100],
			limit:pageSize,
			curr:pageNo,
			layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
			jump: function(obj,first){
				console.log('我是分页')
				pageNo = obj.curr;
				pageSize = obj.limit;
				// getFocusList();
				if(!first){ //首次不执行
					console.log('我执行了分页');
					getUserEvaluation();
				}  
			}
		});
	});
};